package com.jml.蚂蚁.netty.对象序列化client.MsgpackPack编码解码;


import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import java.util.List;
import org.msgpack.MessagePack;

/**
 * @author:jml
 * @date: 2019/12/25 11:02
 * @description：MessagePack解码器
 */
 public class MsgpackDecoder extends MessageToMessageDecoder<ByteBuf> {
	 /**
	  * 服务器解码数据
	  *
	  * @param channelHandlerContext
	  * @param byteBuf
	  * @param list
	  * @throws Exception
	  */
	 @Override
	 protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
		 final int length = byteBuf.readableBytes();
		 byte[] b = new byte[length];
		 byteBuf.getBytes(byteBuf.readerIndex(), b, 0, length);
		 MessagePack msgpack = new MessagePack();
		 list.add(msgpack.read(b));
	 }
 }

